/**
 * Copyright 2014 lerry
 * 
 * All right reserved.
 * 
 * Dec 22, 2014
 */
package com.bac.bacplatform;

import com.android.volley.Response;
import com.android.volley.Response.Listener;
import com.bac.javabeans.Principal;
import com.bac.utils.Config;
import com.bac.utils.Util;
import com.google.gson.Gson;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * 个人资料
 * @author lerry
 *
 */
public class PersonalProfileActivity extends BaseActivity implements OnClickListener{
	
	private TextView mPhoneTV,mIdentityTV,mRegisterTv;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.personal_message);
		
		mPhoneTV = (TextView)findViewById(R.id.personal_phone_num);
		mIdentityTV = (TextView)findViewById(R.id.personal_identity_num);
		mRegisterTv = (TextView)findViewById(R.id.personal_register_date);
		getCurrentuser();
	}

	@Override
	public void init() {
		RelativeLayout rl_personal_address = (RelativeLayout) findViewById(R.id.personal_address);
		rl_personal_address.setOnClickListener(this);
		
		RelativeLayout rl_personal_email = (RelativeLayout) findViewById(R.id.personal_email);
		rl_personal_email.setOnClickListener(this);
		
		findViewById(R.id.title_left).setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.personal_address:
			Intent intentToAddressActivity = new Intent(PersonalProfileActivity.this,AddressActivity.class);
			startActivity(intentToAddressActivity);
			break;
		case R.id.personal_email:
			Intent intentToEamilActivity = new Intent(PersonalProfileActivity.this,EmailActivity.class);
			startActivity(intentToEamilActivity);
			break;
		case R.id.title_left:
			finishActivityOut();
			break;
		default:
			break;
		}
		
	}
	
	public void getCurrentuser() {
		/**
		 * 成功返回结果
		 */
		Listener<String> sL = new Response.Listener<String>() {
			@Override
			public void onResponse(String response) {
				dismissLoadingProgressNow();
				Log.i("TAG----success", response.toString());
				
				Gson gson = new Gson();
				Principal principal = gson.fromJson(response, Principal.class);
				mPhoneTV.setText(principal.getPhone());
				mIdentityTV.setText(principal.getIdCard());
				mRegisterTv.setText(principal.getRegisterDate());
			}
		};
		showLoadingProgress();
		
		String path = Config.URL_CURRENT_USER;
		Util.httpRequestToGet(path, sL, this);
	}

}
